package com.whnk.web.controller.pm;

import java.util.Arrays;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.pm.domain.IncomeInfo;
import com.whnk.pm.service.IIncomeInfoService;

/**
 * 确认单 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-07-24
 */
@Controller
@RequestMapping("/pm/incomeInfo")
public class IncomeInfoController extends BaseController
{
    private String prefix = "pm/incomeInfo";
	
	@Autowired
	private IIncomeInfoService incomeInfoService;
	
	@RequiresPermissions("pm:incomeInfo:view")
	@GetMapping()
	public String incomeInfo()
	{
	    return prefix + "/incomeInfo";
	}
	
	/**
	 * 查询确认单列表
	 */
	@RequiresPermissions("pm:incomeInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IncomeInfo incomeInfo)
	{
		startPage();
        List<IncomeInfo> list = incomeInfoService.selectIncomeInfoList(incomeInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增确认单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存确认单
	 */
	@RequiresPermissions("pm:incomeInfo:add")
	@Log(title = "确认单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IncomeInfo incomeInfo)
	{		
		return toAjax(incomeInfoService.insertIncomeInfo(incomeInfo));
	}

	/**
	 * 修改确认单
	 */
	@GetMapping("/edit/{incId}")
	public String edit(@PathVariable("incId") Integer incId, ModelMap mmap)
	{
		IncomeInfo incomeInfo = incomeInfoService.selectIncomeInfoById(incId);
		mmap.put("incomeInfo", incomeInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存确认单
	 */
	@RequiresPermissions("pm:incomeInfo:edit")
	@Log(title = "确认单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IncomeInfo incomeInfo)
	{		
		return toAjax(incomeInfoService.updateIncomeInfo(incomeInfo));
	}
	
	/**
	 * 删除确认单
	 */
	@RequiresPermissions("pm:incomeInfo:remove")
	@Log(title = "确认单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(incomeInfoService.deleteIncomeInfoByIds(ids));
	}
	
	/**
	 * 查看详细信息
	 * 
	 * @param incId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("pm:incomeInfo:detail")
    @GetMapping("/detail/{incId}")
    public String detail(@PathVariable("incId") Integer incId, ModelMap mmap)
	{
		IncomeInfo incomeInfo = incomeInfoService.selectIncomeInfoById(incId);
		mmap.put("incomeInfo", incomeInfo);
        return prefix + "/detail";
    }
	
	/**
	 * 查看确认单信息
	 * 
	 * @param incId
	 * @param mmap
	 * @return
	 */
	@GetMapping("/queryDetail/{incId}")
    public String queryDetail(@PathVariable("incId") Integer incId, ModelMap mmap)
    {
		IncomeInfo incomeInfo = incomeInfoService.selectIncomeInfoById(incId);
		mmap.put("incomeInfo", incomeInfo);
        return "pm/incomeDetail/incomeDetail";
    }

	@Log(title = "确认单", businessType = BusinessType.OTHER)
	@PostMapping("/generateIncomeDetail")
	@ResponseBody
    public AjaxResult generateIncomeDetail(String ids) {
		List<String> listId = Arrays.asList(ids.split(","));
		incomeInfoService.generateIncomeDetail(listId);
		return success();
	}
}
